//
//  NeighbouringDetailCell.m
//  HeartTravel
//
//  Created by dlios on 15-7-1.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "NeighbouringDetailCell.h"
#import "NeighbouringDetailTableCell.h"
#import "HTTPTool.h"
#import "NeighbouringModel.h"
#import "UIImageView+WebCache.h"

@implementation NeighbouringDetailCell

- (void)dealloc{
    [_stayArr release];
    [_restaurantArr release];
    [_amuseArr release];
    [_shopingArr release];
    [_scenicArr release];
    [_allArr release];
    [_temp release];
    [_tableView release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self create];
    }
    return self;
}

- (void)setAllArr:(NSMutableArray *)allArr{
    if (self.allArr != allArr) {
        [_allArr release];
        _allArr = [allArr retain];
    }
}

- (void)setScenicArr:(NSMutableArray *)scenicArr{
    if (self.scenicArr != scenicArr) {
        [_scenicArr release];
        _scenicArr = [scenicArr retain];
    }
}


- (void)setStayArr:(NSMutableArray *)stayArr{
    if (self.stayArr != stayArr) {
        [_stayArr release];
        _stayArr = [stayArr retain];
    }
}

- (void)setRestaurantArr:(NSMutableArray *)restaurantArr{
    if (self.restaurantArr != restaurantArr) {
        [_restaurantArr release];
        _restaurantArr = [restaurantArr retain];
    }
}

- (void)setAmuseArr:(NSMutableArray *)amuseArr{
    if (self.amuseArr != amuseArr) {
        [_amuseArr release];
        _amuseArr = [amuseArr retain];
    }
    
}

- (void)setShopingArr:(NSMutableArray *)shopingArr{
    if (self.shopingArr != shopingArr) {
        [_shopingArr release];
        _shopingArr = [shopingArr retain];
    }
}

- (void)setTemp:(NSString *)temp{
    
    if (self.temp != temp) {
        [_temp release];
        _temp = [temp retain];
    }
    
    [self.tableView reloadData];
}

- (void)create{
    
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height) style:UITableViewStylePlain];

    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = [UIColor grayColor];
    self.tableView.showsVerticalScrollIndicator = NO;
    
    [self.contentView addSubview:self.tableView];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NeighbouringModel *model = [[NeighbouringModel alloc]init];
    
    static NSString *reuse = @"detailReuse";
    NeighbouringDetailTableCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[[NeighbouringDetailTableCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse]autorelease];
    }
    if ([self.temp isEqualToString:@"全部"]) {
        
        model = self.allArr[indexPath.row];
        cell.titleLabel.text = model.name;
        [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_s]];
        cell.tipsLabel.text = model.bDescription;
        NSNumber *numberTemp = model.distance;
        double distanceTemp = numberTemp.doubleValue;
        
        cell.distanceLabel.text = [NSString stringWithFormat:@"距我 %ld 米 / %ld 人去过",((NSInteger)(distanceTemp * 1000)),model.visited_count];
;
    }else if([self.temp isEqualToString:@"景点"]){
        
        
        model = self.scenicArr[indexPath.row];
        cell.titleLabel.text = model.name;
        [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_s]];
        cell.tipsLabel.text = model.bDescription;
        NSNumber *numberTemp = model.distance;
        double distanceTemp = numberTemp.doubleValue;
        cell.distanceLabel.text = [NSString stringWithFormat:@"距我 %ld 米 / %ld 人去过",((NSInteger)(distanceTemp * 1000)),model.visited_count];
        
        
        
    }else if([self.temp isEqualToString:@"住宿"]){
        
        model = self.stayArr[indexPath.row];
        cell.titleLabel.text = model.name;
        [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_s]];
        cell.tipsLabel.text = model.bDescription;
        NSNumber *numberTemp = model.distance;
        double distanceTemp = numberTemp.doubleValue;
        cell.distanceLabel.text = [NSString stringWithFormat:@"距我 %ld 米 / %ld 人去过",((NSInteger)(distanceTemp * 1000)),model.visited_count];
        
        
    }else if ([self.temp isEqualToString:@"餐厅"]){
        
        
        
        model = self.restaurantArr[indexPath.row];
        cell.titleLabel.text = model.name;
        [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_s]];
        cell.tipsLabel.text = model.bDescription;
        NSNumber *numberTemp = model.distance;
        double distanceTemp = numberTemp.doubleValue;
        cell.distanceLabel.text = [NSString stringWithFormat:@"距我 %ld 米 / %ld 人去过",((NSInteger)(distanceTemp * 1000)),model.visited_count];
        
        
        
    }else if ([self.temp isEqualToString:@"休闲娱乐"]){
        
        model = self.amuseArr[indexPath.row];
        cell.titleLabel.text = model.name;
        [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_s]];
        cell.tipsLabel.text = model.bDescription;
        NSNumber *numberTemp = model.distance;
        double distanceTemp = numberTemp.doubleValue;
        cell.distanceLabel.text = [NSString stringWithFormat:@"距我 %ld 米 / %ld 人去过",((NSInteger)(distanceTemp * 1000)),model.visited_count];
        
    }else{
        
        model = self.shopingArr[indexPath.row];
        cell.titleLabel.text = model.name;
        [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_s]];
        cell.tipsLabel.text = model.bDescription;
        NSNumber *numberTemp = model.distance;
        double distanceTemp = numberTemp.doubleValue;
        cell.distanceLabel.text = [NSString stringWithFormat:@"距我 %ld 米 / %ld 人去过",((NSInteger)(distanceTemp * 1000)),model.visited_count];
        
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if ([self.temp isEqualToString:@"全部"]) {
        
        return self.allArr.count;
    }else if([self.temp isEqualToString:@"景点"]){
        
        
        return self.scenicArr.count;
        
        
        
        
    }else if([self.temp isEqualToString:@"住宿"]){
        
        return self.stayArr.count;
        
        
    }else if ([self.temp isEqualToString:@"餐厅"]){
        
        
        
        return self.restaurantArr.count;
        
        
        
        
    }else if ([self.temp isEqualToString:@"休闲娱乐"]){
        
        return self.amuseArr.count;
    
        
    }else{
        
        return self.shopingArr.count;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 120;
}



@end
